import 'package:flutter/material.dart';
import 'package:storage/model/warehouse_in_out_model_entity.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';

class WarehouseOutSource extends DataGridSource {
  /// Creates the employee data source class with required details.
  WarehouseOutSource(
      {required List<WarehouseInOutModelEntity> warehouseInData}) {
    _dataList = warehouseInData
        .map<DataGridRow>((e) => DataGridRow(cells: [
              DataGridCell<int>(columnName: 'id', value: e.id),
              DataGridCell<String>(
                  columnName: '商品名称', value: e.goodsName ?? ''),
              DataGridCell<String>(
                  columnName: '商品规格', value: e.goodsSpecification ?? ''),
              DataGridCell<double>(
                  columnName: '商品成本价', value: e.goodsPrice ?? 0),
              DataGridCell<String>(
                  columnName: '出库公司', value: e.companyName ?? ''),
              DataGridCell<double>(
                  columnName: '出库价', value: e.companyPrice ?? 0),
              DataGridCell<int>(columnName: '出库数量', value: e.count ?? 0),
              DataGridCell<String>(
                  columnName: '出库时间', value: e.warehouseTime ?? ''),
            ]))
        .toList();
  }

  List<DataGridRow> _dataList = [];

  @override
  List<DataGridRow> get rows => _dataList;

  @override
  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((e) {
      return Container(
        alignment: Alignment.center,
        decoration: const BoxDecoration(
            border: Border(
          right: BorderSide(color: Colors.grey, width: 1),
          left: BorderSide(color: Colors.grey, width: 1),
        )),
        child: Text(e.value.toString()),
      );
    }).toList());
  }
}
